<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>购物车</title>
    <link rel="shortcut icon" href="img/logo.ico"/>
    <link rel="bookmark" href="img/logo.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="js/httpUtil.js"></script>
    <script src="js/cacheUtil.js"></script>
</head>
<head>

    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta http-equiv="x-dns-prefetch-control" content="on"/>
    <link rel="dns-prefetch" href="//s.stu.126.net"/>
    <link rel="dns-prefetch" href="//mc.stu.126.net"/>
    <link rel="dns-prefetch" href="//mooc.study.163.com"/>
    <link rel="dns-prefetch" href="//imgsize.ph.126.net"/>
    <link rel="dns-prefetch" href="//img0.ph.126.net"/>
    <link rel="dns-prefetch" href="//img1.ph.126.net"/>
    <link rel="dns-prefetch" href="//img2.ph.126.net"/>
    <title>我的购物车</title>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-cache" max-age="0"/>
    <meta http-equiv="Expires" content="0"/>
    <meta name="author" content="Netease"/>
    <meta name="version" content="1.0"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="robots" content="all"/>
    <meta property="wb:webmaster" content="766092f2bbf0c80d"/>
    <meta property="qc:admins" content="22061604124161636375"/>
    <meta name="renderer" content="webkit">
    <meta name="baidu-site-verification" content="BYFmFBILbh"/>
    <meta name="sogou_site_verification" content="OYmk13vRd8"/>
    <meta name="360-site-verification" content="3f6a1f60c79c924896ff3ad0361a7ae4"/>
    <meta name="shenma-site-verification" content="3c734e0249d2a18b010e2f91efebe76e_1456214629"/>
    <meta name="google-site-verification" content="z_KJAVxXT-GQ_nSWb0Vgt3ixceS3si1I8baDikd64uM"/>
    <link rel="stylesheet"
          href="//yktcdn.stu.126.net/so/pub/s/order/web/pt_newpages_common_head_efb5d9d38b83640e5cf3f6e0a7818355.css"/>
    <link rel="stylesheet" name="cssUrl" href="//icon.nosdn.127.net/a75e718e9c6704281a16855bf43a5155.css"/>
    <script src="//yktcdn.stu.126.net/so/pub/s/order/web/pt_newpages_common_common_8cfbc3ee64bce8828f9c4eda84c1397f.js"></script>
    <script type="text/javascript" src="//urswebzj.nosdn.127.net/webzj_cdn101/message.js"></script>
    <script src="//yktcdn.stu.126.net/so/pub/s/order/web/t_newpages_common_macro_m2_3179b1ae245b255ef841c9b1b90c1794.js"></script>
    <![endif]-->
    <script type="text/javascript">
        window.gaTrackPageview = '_trackPageview';
        window.gaTrackEvent = '_trackEvent';
        window.gaqStr = '_gaq'
    </script>
    <script>
        /*1.获取userId*/
        /*2.发送请求*/
        $(function () {
            let loginUser = getLoginUser();
            let url = "/cart/showCart";
            let param = "userId=" + getLoginUser().id;
            httpGet(url, param, function (resp) {
                console.log("resp is : " + resp);
                /*渲染你的购物车*/
                let loginUser = getLoginUser();
                var total = 0;
                let door = 0;
                for (var index in resp) {
                    $("#cartContent").append('<tr>\n' +
                        //'<th type="checkbox"></th>' +
                        '                <th><img width="300px" height="100px" src="' + resp[index].course.img + '"></th>' +
                        '                <th>' + resp[index].course.name + '</th>\n' +
                        '                <th>' + resp[index].price + '</th>\n' +
                        '            </tr>');

                    door = door + resp[index].cartId + 1;
                    total = total + resp[index].price;
                }
                $("#door").append(door);
                $("#total").append(total);
            })
        })

        function clearCart() {
            let url = "/cart/deleteCart";
            let userId = JSON.parse(localStorage.getItem("login_user")).id;
            let params = "userId=" + userId;
            console.log(params);
            httpGet(url, params, function (data) {
                console.log("清空购物车成功");
                // saveLoginUser(data)
                window.open("shopping.html");
            })
        }

        function succFunction(data) {
            let loginUser = getLoginUser();

            var total;
            for (var cart in data) {
                $("#cartContent").append('<tr>\n' +
                    '<th type="checkbox"></th>' +
                    '                <th><img width="300px" height="300px" src="' + cart.img + '"></th>' +
                    '                <th>' + cart.courseId + '</th>\n' +
                    '                <th>' + cart.price + '</th>\n' +
                    '            </tr>');
                total += cart.price;
            }
            $("#total").text(total);
        }

    </script>


</head>
<body>
<div class="container">
    <!--修复head.html在除依木汗之外的电脑上都不能居中的情况-->
    <iframe src="head.html" frameborder="0" width="100%" height="72" scrolling="No"></iframe>
    <div class="g-flow m-orderCart" id="j-myCart">
        <div class="b-30"></div>
        <h1 class="f-f0 head">我的购物车 <span class="f-fc9 f-fs0">共<span class="" id="door"></span>门课程</span></h1>
        <div class="b-20"></div>
        <!--Regular if100-->
        <div class="u-emptybig">
            <p class="emptytext">好好学习，天天向上，看到喜欢的课程，点击【加入购物车】，在这里合并购买</p>
        </div>
    </div>
    <div class="row" style="margin-top: 40px;">
        <div class="col-md-10 col-md-offset-1">
            <table class="table table-bordered table-striped table-hover" id="cartContent">
                <tr>
                    <!--                <th id="number"  > 序号</th>-->

                    <th id="cart_id">图片</th>
                    <th>课程名称</th>
                    <th>单价</th>
                </tr>

            </table>
        </div>
    </div>
    <hr>
    <div class="row" id="">
        <div class="pull-right" style="margin-right: 40px;">

            <div style="margin-bottom: 20px;">
                商品金额总计：<span id="total" class="text-danger"></span>
            </div>
            <div>
                <a id="removeAllProduct" onclick="clearCart()" class="btn btn-default btn-lg">清空购物车</a>
                <p class="btn  btn-danger btn-lg" onclick="startOrder()">去结算</p>
            </div>
            <br><br>
        </div>
    </div>
    <div class="m-maintainInfo f-dn">
        <div id='maintain_info_box' class='g-flow'></div>
    </div>
    <div id='advertisement_box' class="m-advertisement f-pf f-dn"></div>
    <div class="g-flow m-orderCart" id="j-yCart">
    </div>
    <iframe src="bottom.html" frameborder="0" width="100%" height="200" scrolling="No"></iframe>

</div>

<script>
    function startOrder() {
        /*1.获取[1.price 2.订单号 3.订单名称]
        * 2.发送请求  */
        /*1.获取所有购物车的物品*/
        /*
        * from : shopping.html
        * param : userId
        * to : /cart/showAll
        * param : totalPrice
        *
        * */
        let course = JSON.parse(sessionStorage.getItem("course"));
        let order_price = $("#total")[0].innerHTML;
        let order_Name = "empty shopping html";
        let order_ID = getOrderId();
        let url = "/order/start";
        let params = {
            WIDout_trade_no: order_ID,
            WIDtotal_amount: order_price,
            WIDsubject: order_Name,
            WIDbody: "kevin pay demo",
            passback_params: course.id
        };
        console.log("params is : " + params.valueOf());
        console.log("param.json is : " + JSON.stringify(params));
        httpGetHtml(url, params, function (resp) {
            console.log("alipay resp is : " + resp);
            $('body').append(resp);
            $("form").attr("target", "_blank");
        })
    }

    function getOrderId() {
        let vNow = new Date();
        let sNow = "";
        sNow += String(vNow.getFullYear());
        sNow += String(vNow.getMonth() + 1);
        sNow += String(vNow.getDate());
        sNow += String(vNow.getHours());
        sNow += String(vNow.getMinutes());
        sNow += String(vNow.getSeconds());
        sNow += String(vNow.getMilliseconds());
        return sNow;
    }
</script>
</body>
</html>